package lancs.mobilemedia.core.ui.controller;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Image;

import lancs.mobilemedia.core.ui.screens.PhotoViewScreen;
import lancs.mobilemedia.lib.exceptions.ImageNotFoundException;
import lancs.mobilemedia.lib.exceptions.PersistenceMechanismException;

public class DefaultShowImageController implements ShowImageController {

	public void showImage(PhotoController photoController, String imageName) {
		Image storedImage = null;
		try {
			storedImage = photoController.getAlbumData().getImageFromRecordStore(photoController.getCurrentStoreName(), imageName);
		} catch (ImageNotFoundException e) {
			Alert alert = new Alert("Error", "The selected photo was not found in the mobile device", null, AlertType.ERROR);
			Display.getDisplay(photoController.getMidlet()).setCurrent(alert, Display.getDisplay(photoController.getMidlet()).getCurrent());
			return;
		} catch (PersistenceMechanismException e) {
			Alert alert = new Alert("Error", "The mobile database can open this photo", null, AlertType.ERROR);
			Display.getDisplay(photoController.getMidlet()).setCurrent(alert, Display.getDisplay(photoController.getMidlet()).getCurrent());
			return;
		}

		PhotoViewScreen canv = new PhotoViewScreen(storedImage);
		canv.setCommandListener(photoController);

		addCopyPhotoAbility(photoController, imageName, canv);

		photoController.setCurrentScreen(canv);
	}

	public void addCopyPhotoAbility(PhotoController photoController, String imageName, PhotoViewScreen canv) {

	}

}